FROM node:latest

WORKDIR /app
ENV NODE_ENV production

COPY . /app
RUN touch /app/.env

RUN npm install

ARG SHORT_COMMIT_HASH
ENV NEXT_PUBLIC_SHORT_COMMIT_HASH=$SHORT_COMMIT_HASH

ARG POSTHOG_KEY
ENV NEXT_PUBLIC_POSTHOG_KEY=$POSTHOG_KEY

ARG NEXT_PUBLIC_NO_PAYMENT_REQUIRED
ENV NEXT_PUBLIC_NO_PAYMENT_REQUIRED=$NEXT_PUBLIC_NO_PAYMENT_REQUIRED

ARG NEXT_PUBLIC_ENABLE_GOOGLE_OAUTH
ENV NEXT_PUBLIC_ENABLE_GOOGLE_OAUTH=$NEXT_PUBLIC_ENABLE_GOOGLE_OAUTH

ARG NEXT_PUBLIC_ENABLE_GITHUB_OAUTH
ENV NEXT_PUBLIC_ENABLE_GITHUB_OAUTH=$NEXT_PUBLIC_ENABLE_GITHUB_OAUTH

ARG GOOGLE_KEYPATH
COPY $GOOGLE_KEYPATH /app/keyfile.json
ENV GOOGLE_APPLICATION_CREDENTIALS=/app/keyfile.json

RUN npx next telemetry disable
RUN npm run build

EXPOSE 3000

CMD ["npm", "run", "start"]
